package com.cwj.controller;

import com.cwj.controller.utils.Code;
import com.cwj.controller.utils.Result;
import com.cwj.pojo.User03;
import com.cwj.service.NetworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ACER
 */
@Controller()
public class NetworkController2 {

    @Autowired
    private NetworkService networkService;

    @RequestMapping("/setMessage")
    @ResponseBody
    public Result test(String message){
        networkService.setMessage(message);
        return new Result(Code.SAVE_OK,null,"留言成功");
    }

    @RequestMapping("/numSQL")
    @ResponseBody
    public Result numSQL(String uid){
        System.out.println(uid);
        return new Result(Code.GET_OK,networkService.numSQL(uid),null);
    }

    @RequestMapping("/strSQL")
    @ResponseBody
    public Result strSQL(String uid){
        return new Result(Code.GET_OK,networkService.strSQL(uid),null);
    }

    @RequestMapping("/getUser")
    public String getUser(String username, Model model, HttpServletRequest request){
        User03 user03 = networkService.getUser03(username);
        model.addAttribute("username",user03.getUsername());
        model.addAttribute("password",user03.getPassword());
        model.addAttribute("sex",user03.getSex());
        model.addAttribute("address",user03.getAddress());
        model.addAttribute("telephone",user03.getTelephone());
        return "/pages/visit_details.jsp";
    }


}
